package com.yxhl.zoume.core.func.webpage.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.yxhl.zoume.R;
import com.yxhl.zoume.UIConstants;
import com.yxhl.zoume.common.ui.activity.base.BaseActivityWithToolBar;
import com.yxhl.zoume.core.func.webpage.fragment.HTMLFragment;
import com.yxhl.zoume.core.func.webpage.fragment.WebViewFragment;
import com.yxhl.zoume.core.func.webpage.info.WebPageEntrance;

/**
 * 管理静态页面的activity
 * Created by vhawk on 16/4/12.
 */
public class WebPageActivity extends BaseActivityWithToolBar {

    private WebPageEntrance mEntrance;

    public static Intent getCallingIntent(Context context, WebPageEntrance entrance) {
        Intent intent = new Intent(context, WebPageActivity.class);
        intent.putExtra(UIConstants.UserContainer.ARGUMENT_KEY_ENTRANCE_TYPE, entrance);
        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handleIntent();
        initializeShow();
    }

    private void handleIntent() {
        Intent intent = getIntent();
        if (intent != null) {
            mEntrance = (WebPageEntrance) intent.getSerializableExtra(UIConstants.UserContainer.ARGUMENT_KEY_ENTRANCE_TYPE);
        }
    }

    private void initializeShow() {
        if (mEntrance != null) {
            String url = mEntrance.getUrl();
            if (TextUtils.isEmpty(url)) {
                addFragment(R.id.fragment_container, HTMLFragment.newInstance(mEntrance));
            } else {
                addFragment(R.id.fragment_container, WebViewFragment.newInstance(mEntrance));
            }
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        overridePendingTransition(R.anim.left_enter, R.anim.right_out);
    }


    @Override
    protected int getLayoutResId() {
        return R.layout.activity_func_intorduction;
    }

    @Override
    protected void initializeInjector() {

    }

    @Override
    protected void onHeaderLeftClick(View view) {
        onBackPressed();
    }

    @Override
    protected void onHeaderRightClick(View view) {

    }
}
